package com.zhangshuo.patternDesign.memento;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * Created by shuo.zhang on 2017-10-27.
 */
public class Person {
    private String name;
    private List<String> memories ;

    public Person(String name) {
        this.name = name;
        this.memories = new ArrayList<>();
    }

    /**
     * 新增记录
     * @param memory
     */
    public void addMemory(String memory){
        this.memories.add(memory);
    }

    /**
     * 新增多个记录
     * @param collection
     */
    public void addMemory(Collection<? extends String> collection){
        this.memories.addAll(collection);

    }

    /**
     *
     * @return 返回不可修改的记录列表
     */
    public List<String> getMemories() {
        return Collections.unmodifiableList(this.memories);
    }


    /**
     * 还原记忆
     * @param memento
     */
    public void setMemento(Memento memento) {
        this.memories = memento.getMemories();
    }

    /**
     * 生成记忆
     * @return
     */
    public Memento getMemento() {
        Memento memento = new Memento();
        memento.setMemories(new ArrayList<>(this.memories));
        return memento;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", memories=" + memories +
                '}';
    }
}
